<template>
	<view class="home">
		<view class="headertop" :style="{'background':back1}">
			<view class="topdaohang" :style="{'margin-top':statusBarHeight+'px','height':barHeight+'px'}">
				<span>企址易</span>
			</view>
		</view>

		<view class="loop">
			<up-swiper height="358" :list="list5" autoplay @change="e => current = e.current" @click="clickloop"
				:autoplay="true">
				<template #indicator>
					<view class="indicator">
						<view class="indicator__dot" v-for="(item, index) in list5" :key="index"
							:class="[index === current && 'indicator__dot--active']">
						</view>
					</view>
				</template>
			</up-swiper>
		</view>
		<view :style="{'margin-top':statusBarHeight+'px','height':barHeight+'px'}">

		</view>
		<view class="bottomcontent">
			<view class="center">
				<view class="seachbox">
					<view class="leftcity" @click="getdizhi">
						<span style="width: 100rpx;text-align: center;">{{query1.area?query1.area:'请选择'}}</span>
						<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/微信图片_20250804100846.png"
							class="icon" mode=""></image>
					</view>
					<image src="/static/images/Frame@2x.png" class="iconinput" mode=""></image>
					<input v-model="query.keywords" @confirm="ss('搜索')" type="search" placeholder="请输入关键词进行搜索" />
					<!-- v-if="query.keywords" -->
					<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/删除(1).png" v-if="query.keywords"
						@click="qk" class="iconrem" mode="">
					</image>
				</view>
				<view class="rw">
					<view class="numrw" v-if="homeobj.msgnum">
						{{homeobj.msgnum}}
					</view>
					<view class="lookbtn" @click="gopage('每日任务')">
						<span>查看任务</span>
					</view>
					<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/Group 11846@2x.png" mode="widthFix">
					</image>
				</view>
				<view class="titleline">
					<view class="kuai">

					</view>
					<view class="title">
						合作项目展示
					</view>
				</view>
				<view class="contents">
					<view class="msgicon" v-if="!list.length">
						<image :src="_static('https://jingwei.xunfuzhifuzaixian.com/static/images/wxnone.png')"
							mode="widthFix">
						</image>
						<view class="msgtext">
							暂无内容
						</view>
					</view>

					<view class="itembox" v-for="(item,index) in list" :key="index" @click="gopage(item.id)">
						<view class="chengshidh">
							<image class="dhicon" src="/static/images/Frame@2x(1).png" mode="">
							</image>
							<view class="address">
								{{item.address}}
							</view>
						</view>
						<image :src="item['image']" class="img1" mode=""></image>
						<view class="texts">
							<view class="t1">
								{{item['title']}}
							</view>
							<view class="t2">
								{{item['detail']}}
							</view>
							<view class="t3">
								<span style="font-weight: bold;font-size: 32rpx;color: #F53F3F;">{{item.price}}</span>
								<!-- <span
									style="font-weight: 400;font-size: 20rpx;color: #86909C;margin-left: 4rpx;">元/㎡</span> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view style="height: 200rpx;">

		</view>
		<userlogin ref="denglu"></userlogin>
		<up-picker :show="show" ref="uPickerRef" cancelText="重置" :defaultIndex="defaultGroupIndex" :columns="areaList"
			keyName="name" @cancel="cancel" @confirm="confirm" @change="changeHandler" v-if="show"></up-picker>
		<Tabbar page="/pages/index/index"></Tabbar>
	</view>
</template>

<script setup>
	import userlogin from '@/components/getuser/getuser.vue'
	import ulm, {
		$api
	} from '@/ulm';
	import {
		getToken,
		setToken
	} from '@/ulm/utils/auth';
	import Tabbar from '@/components/tabbar.vue'
	import {
		_static
	} from '@/ulm/utils/url.js'
	import {
		ref,
		onMounted,
		reactive,
	} from 'vue'
	import {
		onLoad,
		onShow,
		onPageScroll,
		onReachBottom,
		onPullDownRefresh
	} from "@dcloudio/uni-app";
	const homeobj = ref({})
	const current = ref(0)
	const denglu = ref(null)
	const defaultGroupIndex = ref([1, 2])
	const years = []
	const uPickerRef = ref(null)
	const show = ref(false)
	const months = []
	const days = []
	var areaList = reactive([])
	const statusBarHeight = ref('')
	const back1 = ref('')
	const indicatorStyle = ref(`height: 50px;`)
	const list = ref([])
	const nexttime = ref('')
	const total = ref(0)
	const query1 = reactive({
		province: '',
		city: '',
		cityid: '',
		area: ''
	})

	const query = reactive({
		page: 1,
		limit: 10,
		cityid: '',
		keywords: '',
	})
	const barHeight = ref('')
	const list5 = ref([
		_static('https://jingwei.xunfuzhifuzaixian.com/static/images/Group 11845@2x.png'),
		_static('https://jingwei.xunfuzhifuzaixian.com/static/images/Group 11845@2x.png')
	]);

	onPullDownRefresh(() => {
		console.log('下拉刷新触发');
		query.page = 1
		list.value = []
		xmList()
		setTimeout(() => {
			// 数据加载完成后停止刷新
			uni.stopPullDownRefresh();
			console.log('刷新完成');
		}, 1000);
	})

	function clickloop(e) {
		console.log(homeobj.value, 'homeobj.valuehomeobj.valuehomeobj.value');
		uni.navigateTo({
			url: '/sub_index/index/xmdetail?id=' + homeobj.value['banner'][e]['typeid']
		})
	}

	function getdizhi() {

		setTimeout(() => {
			var s = 0
			var s1 = areaList[0][s]['son'].findIndex(item => item.name == query1
				.city)
			if (s1 == -1) {
				s1 = 0
			}
			var s2 = areaList[0][s]['son'][s1]['son']
				.findIndex(item => item.name == query1.area)
			if (s2 == -1) {
				s2 = 0
			}

			defaultGroupIndex.value = [s, s1, s2]
			console.log(defaultGroupIndex.value, query1.city, areaList[0][s]['son'],
				'defaultGroupIndex.valuedefaultGroupIndex.valuedefaultGroupIndex.value');

			uPickerRef.value.setColumnValues(1, areaList[0][s].son);
			uPickerRef.value.setColumnValues(2, areaList[0][s].son[s1].son);
		}, 500)
		console.log(defaultGroupIndex);
		show.value = true
	}


	const changeHandler = (e) => {
		const {
			columnIndex,
			value,
		} = e;
		let city = value[0].son

		if (columnIndex === 0) {
			uPickerRef.value.setColumnValues(1, city);
			uPickerRef.value.setColumnValues(2, city[0].son);
		} else if (columnIndex === 1) { // 市变化更新区/县列表
			uPickerRef.value.setColumnValues(2, value[1].son);
		}
	};

	function ss() {
		query.page = 1
		list.value = []
		xmList()
	}
	const cancel = () => {
		uni.removeStorageSync('cityname')
		query.cityid = ''
		query1['province'] = ''
		query1['city'] = ''
		query1['area'] = ''
		query1.cityid = ''
		show.value = false;
		query.page = 1
		list.value = []
		xmList()
	}

	function qk() {
		query.keywords = ''
		query.page = 1
		list.value = []
		xmList()

	}
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#CAEEFF'
		} else {
			back1.value = ''
		}
	})
	onShow(() => {
		if (uni.getStorageSync('cityname')) {
			var obj = uni.getStorageSync('cityname')

			query1['area'] = obj.area
			query1['province'] = obj.province
			query1['city'] = obj.city
			query1['cityid'] = obj.cityid
			query['cityid'] = obj.cityid
			query1['city'] = obj.city

		} else {
			query1['province'] = ''
			query1['city'] = ''
			query1['cityid'] = ''
			query['cityid'] = ''
		}


		if (getToken()) {
			initmessage()
		}
		bannerinit()
		query.page = 1
		list.value = []
		xmList()
		allareainit()
	})
	const confirm = (e) => {
		let {
			value
		} = e
		console.log(value, 'valuevaluevalue');
		query1['province'] = value[0]['name']
		query1['city'] = value[1]['name']
		query1.cityid = value[2]['id']
		query.cityid = value[2]['id']
		query1.area = value[2]['name']
		uni.setStorageSync('cityname', query1)
		query.page = 1
		list.value = []
		xmList()
		console.log(value, 'value---------------');
		show.value = false
	}
	onReachBottom(() => {
		if (total.value > list.value.length) {
			query.page++
			xmList()
		}
	})

	function getLocation() {
		uni.getLocation({
			type: 'gcj02',
			success: (res) => {
				console.log(res, 'res-----------------');
			},
			fail: (err) => {
				uni.showToast({
					title: '获取定位失败',
					icon: 'none'
				})
			}
		});
	}
	async function allareainit() {
		const res = await $api.allarea()
		if (res.code == 1) {
			areaList = reactive([res.data])
		}
	}
	async function xmList() {
		const res = await $api.hoselist({
			is_shouye: 1,
			page: query['page'],
			limit: query['limit'],
			keywords: query['keywords'],
			cityid: query['cityid']
		})
		if (res.code == 1) {
			total.value = res.data.count
			list.value.push(...res.data.list)
		}
	}

	async function initmessage() {
		const res = await $api.dayrenwu()
		if (res.code == 1) {

		}
	}
	async function bannerinit() {
		const res = await $api.banner()
		if (res.code == 1) {
			homeobj.value = res.data
			list5.value = res.data.banner.map(item => item.image)
		}
	}

	function gopage(str) {
		if (!getToken()) {
			denglu.value.DengLu()
			return
		}
		if (str == '每日任务') {
			uni.navigateTo({
				url: '/sub_index/index/everydayrenwu'
			})
		} else {
			uni.navigateTo({
				url: '/sub_index/index/xmdetail?id=' + str
			})
		}

	}
</script>

<style lang="scss">
	.msgicon {
		width: 608rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 608rpx;
		}
	}

	.xuanxiang {
		width: 100%;
		display: flex;
		align-items: center;
		margin-top: 30rpx;
		overflow: hidden;
		justify-content: space-between;
		margin-bottom: 30rpx;

		.tt {
			font-size: 32rpx;
		}
	}

	page {
		background: #F7F8FA;
	}

	.home {
		width: 100%;
		overflow: hidden;


		.headertop {
			width: 100%;
			position: fixed;
			top: 0%;
			overflow: hidden;
			transition: 0.5s;
			z-index: 9999;

			.topdaohang {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 500;
				font-size: 34rpx;
				color: #1D2129;
			}
		}

		.loop {
			width: 100%;
			overflow: hidden;
			position: absolute;
			z-index: 0;
			background: linear-gradient(180deg, #FFFFFF 92%, rgba(255, 255, 255, 0) 100%);


		}

		.bottomcontent {
			width: 100%;
			margin-top: 482rpx;
			overflow: hidden;
			position: relative;
			z-index: 999;

			.center {
				width: 686rpx;
				margin: auto;

				.rw {
					width: 100%;
					overflow: hidden;
					margin-top: 20rpx;
					position: relative;

					image {
						width: 100%;
					}

					.lookbtn {
						width: 162rpx;
						height: 56rpx;
						background: #0B5FA9;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						text-align: center;
						line-height: 56rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #FFFFFF;
						position: absolute;
						margin-left: 36rpx;
						margin-top: 114rpx;

					}

					.numrw {
						margin-top: 100rpx;
						margin-left: 160rpx;
						padding: 0 12rpx;
						height: 28rpx;
						background: #FF941A;
						box-shadow: 0rpx 2rpx 4rpx 0rpx rgba(13, 88, 154, 0.47);
						border-radius: 14rpx 14rpx 14rpx 0rpx;
						text-align: center;
						line-height: 28rpx;
						font-weight: bold;
						font-size: 22rpx;
						color: #FFFFFF;
						position: absolute;
						z-index: 99;
					}
				}

				.contents {
					width: 100%;
					overflow: hidden;
					display: flex;
					flex-wrap: wrap;
					margin-top: 28rpx;

					.itembox:nth-child(2n) {
						margin-right: 0rpx !important;
					}

					.itembox {
						width: 326rpx;
						background: #FFFFFF;
						box-shadow: 0rpx 4rpx 14rpx 0rpx rgba(0, 0, 0, 0.08);
						border-radius: 20rpx;
						overflow: hidden;
						position: relative;
						margin-bottom: 28rpx;
						margin-right: 32rpx;

						.chengshidh {
							height: 46rpx;
							background: rgba(15, 15, 15, 0.47);
							border-radius: 0rpx 0rpx 0rpx 0rpx;
							width: 100%;
							display: flex;
							align-items: center;
							position: absolute;
							margin-top: 226rpx;

							.dhicon {
								width: 24rpx;
								height: 24rpx;
								margin-left: 16rpx;
							}

							.address {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #FFFFFF;
								margin-left: 2rpx;
								white-space: nowrap;
								/* 禁止换行 */
								overflow: hidden;
								/* 隐藏溢出内容 */
								text-overflow: ellipsis;
								/* 超出用省略号表示 */
								width: 280rpx;
								/* 设置容器宽度 */
							}
						}

						.img1 {
							width: 328rpx;
							height: 272rpx;

						}

						.texts {
							width: 296rpx;
							margin: auto;
							margin-top: 16rpx;

							.t1 {
								font-family: PingFang SC, PingFang SC;
								font-weight: bold;
								font-size: 28rpx;
								color: #1D2129;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								width: 100%;
							}

							.t2 {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
								color: #4E5969;
								width: 100%;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}

							.t3 {
								margin-bottom: 24rpx;
							}
						}
					}
				}

				.titleline {
					width: 100%;
					display: flex;
					align-items: center;

					.kuai {
						width: 6rpx;
						height: 32rpx;
						background: #23ACED;
						border-radius: 0rpx 12rpx 12rpx 0rpx;
					}

					.title {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 36rpx;
						color: #1D2129;
						margin-left: 8rpx;
					}
				}

				.seachbox {
					width: 100%;
					height: 88rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 0rpx 27rpx 0rpx rgba(0, 0, 0, 0.13);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					display: flex;
					position: relative;
					align-items: center;

					.iconrem {

						position: absolute;
						width: 40rpx;
						height: 40rpx;
						right: 30rpx;
					}

					.iconinput {
						width: 32rpx;
						height: 32rpx;
						margin-left: 20rpx;
					}

					input {
						font-size: 28rpx;
						margin-left: 14rpx;
					}

					.leftcity {
						display: flex;
						align-items: center;
						width: 176rpx;
						height: 52rpx;
						border-right: 2rpx solid #C9CDD4;
						justify-content: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #4E5969;

						.icon {
							width: 20rpx;
							height: 12rpx;
							margin-left: 8rpx;
						}
					}
				}
			}

		}

		::v-deep .u-swiper__indicator {
			bottom: 72rpx !important;
		}

		.indicator {
			@include flex(row);
			justify-content: center;

			&__dot {
				width: 20rpx;
				height: 8rpx;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				background: rgba(255, 255, 255, 0.38);
				margin: 0 2px;
				transition: background-color 0.3s;

				&--active {
					width: 36rpx;
					height: 8rpx;
					background-color: #FFFFFF;
				}
			}
		}

		.indicator-num {
			padding: 2px 0;
			background-color: rgba(0, 0, 0, 0.35);
			border-radius: 100px;
			width: 35px;
			@include flex;
			justify-content: center;

			&__text {
				color: #FFFFFF;
				font-size: 12px;
			}
		}

	}
</style>